package com.pro.controller;

import com.pro.pojo.*;
import com.pro.service.SystemIndexService;
import com.pro.utils.InformationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Map;

/**
 * @Author 谭金诚
 * @Description TODO
 * @Date 2022/1/7 16:04
 * @Version 1.0
 */
@Controller
@RequestMapping("/systemIndex")
public class SystemIndexController {

    @Autowired
    private SystemIndexService systemIndexService;

    /**
     * @ClassName getSystemIndexNums
     * @Author 谭金诚
     * @Date 2022/1/7
     */
    @RequestMapping("/getSystemIndexNums")
    @ResponseBody
    public JsonData getSystemIndexNums(){
        OrderQuantity systemIndexNums = systemIndexService.getSystemIndexNums();
        return systemIndexNums != null ? JsonData.buildSuccess(systemIndexNums) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getBeforeUserNums
     * @Author 谭金诚
     * @Date 2022/1/10
     */
    @RequestMapping("/getBeforeUserNums")
    @ResponseBody
    public JsonData getBeforeUserNums(String startDate , String endDate){
        Integer beforeUserNums = systemIndexService.getBeforeUserNums(startDate, endDate);
        return beforeUserNums >= 0 ? JsonData.buildSuccess(beforeUserNums) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getNowMonthCourseNums
     * @Author 谭金诚
     * @Date 2022/1/7
     */
    @RequestMapping("/getNowMonthCourseNums")
    @ResponseBody
    public JsonData getNowMonthCourseNums(){
        Map<String, Object> map = systemIndexService.getNowMonthCourseNums();
        return map.size() > 0 ? JsonData.buildSuccess(map) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getNowMonthProductNums
     * @Author 谭金诚
     * @Date 2022/1/10
     */
    @RequestMapping("/getNowMonthProductNums")
    @ResponseBody
    public JsonData getNowMonthProductNums(){
        Map<String, Object> map = systemIndexService.getNowMonthProductNums();
        return map.size() > 0 ? JsonData.buildSuccess(map) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getNowMonthUserNums
     * @Author 谭金诚
     * @Date 2022/1/10
     */
    @RequestMapping("/getNowMonthUserNums")
    @ResponseBody
    public JsonData getNowMonthUserNums(){
        Map<String, Object> map = systemIndexService.getNowMonthUserNums();
        return map.size() > 0 ? JsonData.buildSuccess(map) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getCourseDay
     * @Author 谭金诚
     * @Date 2022/1/9
     */
    @RequestMapping("/getCourseDay")
    @ResponseBody
    public JsonData getCourseDay(){
        Map<String, Object> courseDay = systemIndexService.getCourseDay();
        return courseDay.size() > 0 ? JsonData.buildSuccess(courseDay) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getProductDay
     * @Author 谭金诚
     * @Date 2022/1/10
     */
    @RequestMapping("/getProductDay")
    @ResponseBody
    public JsonData getProductDay(){
        Map<String, Object> courseDay = systemIndexService.getProductDay();
        return courseDay.size() > 0 ? JsonData.buildSuccess(courseDay) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getBeforeUserDay
     * @Author 谭金诚
     * @Date 2022/1/10
     */
    @RequestMapping("/getBeforeUserDay")
    @ResponseBody
    public JsonData getBeforeUserDay(){
        Map<String, Object> courseDay = systemIndexService.getBeforeUserDay();
        return courseDay.size() > 0 ? JsonData.buildSuccess(courseDay) : JsonData.buildError("服务端错误");
    }
    /**
     * @ClassName getCourseStatusNums
     * @Author 谭金诚
     * @Date 2022/1/12
     */
    @RequestMapping("/getCourseStatusNums")
    @ResponseBody
    public JsonData getCourseStatusNums(JsCourse jsCourse){
        JsCourse courseStatusNums = systemIndexService.getCourseStatusNums(jsCourse);
        return courseStatusNums != null ? JsonData.buildSuccess(courseStatusNums) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getSystemIndexInformation
     * @Author 谭金诚
     * @Date 2022/1/23
     * @Return SystemInformation
     * 查询系统信息
     */
    @RequestMapping("/getSystemInformation")
    @ResponseBody
    public JsonData getSystemInformation(HttpServletRequest request, HttpServletResponse response, HttpSession session, SystemInformation systemInformation) throws IOException {
        SystemInformation systemInformation1 = new SystemInformation();
        //mysql版本
        systemInformation.setMysqlVersion(InformationUtils.getMysqlVerseion());
        //服务器名称
        systemInformation.setServerName(InformationUtils.getServerName());
        //服务器地址
        systemInformation.setServerAddress(InformationUtils.getserverAddress());
        //操作系统
        systemInformation.setOperatingSystem(InformationUtils.getOperatingSystem());
        //端口号
        systemInformation.setPortNumber(InformationUtils.getPortNumber(request));
        //获取浏览器名称
        systemInformation.setIeName(InformationUtils.getIeName(request,response,session));
        //获取浏览器版本
        systemInformation.setIeVersion(InformationUtils.getIeVersion(request,response,session));
        return systemInformation != null ? JsonData.buildSuccess(systemInformation): JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName updateUser
     * @Author 谭金诚
     * @Date 2022/1/25
     * @Return boolean
     * 修改用户信息
     */
    @RequestMapping("/updateUser")
    @ResponseBody
    public JsonData updateUser(JsUser user){
        boolean flag = systemIndexService.updateUser(user);
        return flag != false ? JsonData.buildSuccess(flag) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getSystemIndexTeacherNums
     * @Author 谭金诚
     * @Date 2022/1/25
     * @Return OrderQuantity
     * 获取教师首页信息
     */
    @RequestMapping("/getSystemIndexTeacherNums")
    @ResponseBody
    public JsonData getSystemIndexTeacherNums(){
        OrderQuantity systemIndexTeacherNums = systemIndexService.getSystemIndexTeacherNums();
        return systemIndexTeacherNums != null ? JsonData.buildSuccess(systemIndexTeacherNums) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getSystemIndexOperateNums
     * @Author 谭金诚
     * @Date 2022/1/26
     * @Return OrderQuantity
     * 查询运营首页信息
     */
    @RequestMapping("/getSystemIndexOperateNums")
    @ResponseBody
    public JsonData getSystemIndexOperateNums(){
        OrderQuantity systemIndexOperateNums = systemIndexService.getSystemIndexOperateNums();
        return systemIndexOperateNums != null ? JsonData.buildSuccess(systemIndexOperateNums) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getSystemIndexPersonnelMattersNums
     * @Author 谭金诚
     * @Date 2022/1/26
     * @Return OrderQuantity
     * 查询人事首页信息
     */
    @RequestMapping("/getSystemIndexPersonnelMattersNums")
    @ResponseBody
    public JsonData getSystemIndexPersonnelMattersNums(){
        OrderQuantity systemIndexPersonnelMattersNums = systemIndexService.getSystemIndexPersonnelMattersNums();
        return systemIndexPersonnelMattersNums != null ? JsonData.buildSuccess(systemIndexPersonnelMattersNums) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getSystemIndexTeacherOperate
     * @Author 谭金诚
     * @Date 2022/1/27
     * @Return OrderQuantity
     * 查询教师运营首页信息
     */
    @RequestMapping("/getSystemIndexTeacherOperate")
    @ResponseBody
    public JsonData getSystemIndexTeacherOperate(){
        OrderQuantity systemIndexTeacherOperate = systemIndexService.getSystemIndexTeacherOperate();
        return systemIndexTeacherOperate != null ? JsonData.buildSuccess(systemIndexTeacherOperate) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getSystemIndexOperatePersonnelmatters
     * @Author 谭金诚
     * @Date 2022/1/27
     * @Return OrderQuantity
     * 获取运营人事首页信息
     */
    @RequestMapping("/getSystemIndexOperatePersonnelmatters")
    @ResponseBody
    public JsonData getSystemIndexOperatePersonnelmatters(){
        OrderQuantity systemIndexOperatePersonnelmatters = systemIndexService.getSystemIndexOperatePersonnelmatters();
        return systemIndexOperatePersonnelmatters != null ? JsonData.buildSuccess(systemIndexOperatePersonnelmatters) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getSystemIndexPersonnelmattersTeacher
     * @Author 谭金诚
     * @Date 2022/1/28
     * @Return OrderQuantity
     * 获取人事教师首页信息
     */
    @RequestMapping("/getSystemIndexPersonnelmattersTeacher")
    @ResponseBody
    public JsonData getSystemIndexPersonnelmattersTeacher(){
        OrderQuantity systemIndexPersonnelmattersTeacher = systemIndexService.getSystemIndexPersonnelmattersTeacher();
        return systemIndexPersonnelmattersTeacher != null ? JsonData.buildSuccess(systemIndexPersonnelmattersTeacher) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getSystemIndexAll
     * @Author 谭金诚
     * @Date 2022/1/28
     * @Return OrderQuantity
     * 查询教师人事运营首页信息
     */
    @RequestMapping("/getSystemIndexAll")
    @ResponseBody
    public JsonData getSystemIndexAll(){
        OrderQuantity systemIndexAll = systemIndexService.getSystemIndexAll();
        return systemIndexAll != null ? JsonData.buildSuccess(systemIndexAll) : JsonData.buildError("服务端错误");
    }

}
